<template>
  <!-- <nav>
    <RouterLink to="/">Go to Home</RouterLink>
    <RouterLink to="/about">Go to About</RouterLink>
  </nav> -->

  <RouterView />
</template>
<script setup>
import { useSSE } from "@/store/sse";
import { ElMessage } from "element-plus";
const SSEStore = useSSE();
const eventSource = new EventSource(import.meta.env.VITE_SSE_PATH);
// const eventSource = new EventSource("http://127.0.0.1:3333/events");
console.log(eventSource, 68);
// 监听通用消息（未指定 event 类型）
eventSource.onmessage = (e) => {
  // console.log(e.data, "73-layout");
  let data;
  try {
    data = JSON.parse(e.data);
  } catch (error) {
    data = { type: null };
  }
  if (data.type === "msg") {
    ElMessage(data.message);
  } else if (data.type === null) {
  } else {
    SSEStore.setSSEState(data);
  }
};

// 监听特定事件类型（如 event: update）
// eventSource.addEventListener("message", (e) => {
//   console.log(e, 77);
// });

// 错误处理
eventSource.onerror = (e) => {
  console.log("SSE Error:", e);
  eventSource.close();
};
</script>
<style>
*{
  font-family: "HYLingXinTiJ_2";
}
@font-face {
  font-family: 'HYLingXinTiJ_2'; /* 自定义字体名称 */
  src: url('/HYLingXinTiJ_2.ttf') format('truetype');
  font-weight: normal; /* 可选 - 指定字体粗细 */
  font-style: normal; /* 可选 - 指定字体样式 */
}
</style>